<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* 	Class Name	: akun
	Author 		: Iswan Putera S.Kom
	Version		: 1.0
	Date		: 27 May 2013
*/

class Akun extends CI_Controller
{
	function __construct()
	{
		parent::__construct();	
		$this->load->model('main_model');
		$this->load->library('zetro_auth');
		//$this->load->library('zetro_func');
		//force_ssl();
	}

	//kode akun==============================
	function akun_kode()
	{
			$data=array();
			$data['id_akun']=empty($_GET['id_akun'])?'':$_GET['id_akun'];
			$data['tab_header']=$this->zetro_form->generate_tab_header('Kode Akun');
			$this->zetro_form->frm_file('asset/frm/zetro_akun.frm');
			$this->zetro_auth->menus('kode_akun');
			$data['oto']=$this->zetro_auth->cek_oto('c');
			$content='';
			$this->zetro_form->buttons(true,'Simpan');
			$this->zetro_form->section('akun');
			$data['frm']=$this->zetro_form->frm_std('frm1','75%');
			//$data['modal']=$this->zetro_form->dialog($this->zetro_form->frm_std('frm1','70%'),'New Kode Akun');
			//send data to view
			$this->load->view('admin/header');
			$this->load->view('accounting/akun_kode',$data);
			$this->load->view('admin/footer');
	}
	
	function get_akun_list_new()
	{
			//collect data klasifikasi
			$content='';$n=0;
			$ordby=empty($_POST['ordby'])?'cid_parent':$_POST['ordby'];
			$this->main_model->table_name('v_akun_parent');
			$this->main_model->query();
			//$this->main_model->orderby($ordby);
			$this->main_model->set_methods('select');
			$lst_usr=$this->main_model->set_data();
			$this->zetro_auth->menus('kode_akun');
			$content.=($this->zetro_auth->cek_oto('c')!='')?"<div class='nav-pill pull-right'><a href='#' onclick=\"btn_click('f:0','akun');\"><i class='cus-add'></i>".nbs(2)."1st Parent</a></div>":"";
			foreach($lst_usr as $r)
			{
				//collect sub tab 1
				$ordby=empty($_POST['ordby'])?'ckode':$_POST['ordby'];
				$this->main_model->table_name('v_akun_subklas');
				$this->main_model->query();
				$this->main_model->where(array('cid_parent'=>$r->ckode));
				$this->main_model->orderby($ordby);
				$this->main_model->set_methods('select_ordered');
				$sbklas=$this->main_model->set_data();/**/
	
				$n++;$x=0;
			   $content.="<table id='akun' width='100%' class='table table-bordered table-hover'>
			  			<tr  class='tree-toggler alert-info' id='".$r->ckode."'>
			 	 			<td width='80%'><i class='cus-folder-go'></i>".$r->ckode.'. '.$r->cnama."</td>
				 			<td width='15%' align='right'>";
				$content.=($this->zetro_auth->cek_oto('c')!='')?"<i class='cus-folder' onclick=\"btn_click('e:".$r->ckode."','akun');\"></i>":'';
				$content.=($this->zetro_auth->cek_oto('c')!='')?"<i class='cus-add' onclick=\"btn_click('k:".$r->ckode."','akun');\"></i>":'';
				$content.=(empty($sbklas) && $this->zetro_auth->cek_oto('c')!='')?"<i class='cus-delete' onclick=\"btn_click('d:".$r->ckode."','akun');\"></i>":"";
				$content.="</td>
			   			</tr>";
				foreach($sbklas as $rr)
				{
					$x++;$z=0;
					//sub tab 2
					$ordby=empty($_POST['ordby'])?'ckode':$_POST['ordby'];
					$this->main_model->table_name('akun');
					$this->main_model->query();
					$this->main_model->where(array('cid_parent'=>$rr->ckode));
					$this->main_model->orderby($ordby);
					$this->main_model->set_methods('select_ordered');
					$akn=$this->main_model->set_data();/**/
				    $content.="<tr class='tree info-confirm' id='".str_replace('.','_',$rr->ckode)."' >
								<td width='82%'>".nbs(5)."<i class='cus-folder'></i>".$rr->ckode.'. '.$rr->cnama."</td>
								<td width='12%' align='right'>";
					$content.=($this->zetro_auth->cek_oto('e')!='')?"<i class='cus-folder' onclick=\"btn_click('e:".$rr->ckode."','akun');\"></i>":"";
					$content.=($this->zetro_auth->cek_oto('c')!='')?"<i class='cus-add' onclick=\"btn_click('k:".$rr->ckode."','akun');\"></i>":"";
					$content.=(empty($akn) && $this->zetro_auth->cek_oto('e')!='')?"<i class='cus-delete' onclick=\"btn_click('d:".str_replace('.','_',$rr->ckode)."','akun');\"></i>":"";
					$content.="</td>
							</tr>";
					foreach($akn as $rrr)
					{
						$z++;
							//sub tab 3
							$ordby=empty($_POST['ordby'])?'ckode':$_POST['ordby'];
							$this->main_model->table_name('akun');
							$this->main_model->query();
							$this->main_model->where(array('cid_parent'=>$rrr->ckode));
							$this->main_model->orderby($ordby);
							$this->main_model->set_methods('select_ordered');
							$akne=$this->main_model->set_data();/**/
							$content.="<tr class='tree' id='".str_replace('.','_',$rrr->ckode)."' >
											<td width='82%'>".nbs(10)."<i class='cus-folder'></i>".$rrr->ckode.'. '.$rrr->cnama."</td>
											<td width='12%' align='right'>";
							$content.=($this->zetro_auth->cek_oto('e')!='')?"<i class='cus-folder' onclick=\"btn_click('e:".$rrr->ckode."','akun');\"></i>":"";
							$content.=($this->zetro_auth->cek_oto('c')!='')?"<i class='cus-add' onclick=\"btn_click('k:".$rrr->ckode."','akun');\"></i>":"";
							$content.=empty($akne)?"<i class='cus-delete' onclick=\"btn_click('d:".str_replace('.','_',$rrr->ckode)."','akun');\"></i>":"";
							$content.="</td>
							</tr>";
								foreach($akne as $rrre)
								{
									$z++;
									$content.="<tr class='tree' id='".str_replace('.','_',$rrre->ckode)."' >
												<td width='82%'>".nbs(15)."<i class='cus-folder'></i>".$rrre->ckode.'. '.$rrre->cnama."</td>
												<td width='12%' align='right'>";
									$content.=($this->zetro_auth->cek_oto('e')!='')?"<i class='cus-folder' onclick=\"btn_click('e:".$rrre->ckode."','akun');\"></i>":"";
									$content.=($this->zetro_auth->cek_oto('e')!='')?"<i class='cus-delete' onclick=\"btn_click('d:".str_replace('.','_',$rrre->ckode)."','akun');\"></i>":"";
									$content.="</td></tr>";
								}
					}
				}
			}
			  $content.="</table>";
			echo $content;
	}
	function set_akun()
	{
		$data=array();
		$data['cid_parent']=empty($_POST['id_klass'])?'0'	:$_POST['id_klass'];
		$data['igrup'] 	 =empty($_POST['id_calc'])?'0'     :$_POST['id_calc'];
		$data['ckode']   	 =empty($_POST['id_akun'])?'0'     :$_POST['id_akun'];
		$data['cnama']	 =empty($_POST['nm_akun'])?''	 :$_POST['nm_akun'];
		$data['created_by']=$this->session->userdata('userid');
		$this->main_model->prepared_data('akun',$data);
		echo success($this->main_model->set_data());
		
	}
	function del_akun()
	{
		$id=str_replace("_",".",$_POST['id']);
		echo success($this->main_model->hapus_data('akun','ckode',$id));	
	}
	//dropdown klasifikasi
	function get_drdp_klass()
	{
		//echo $this->zetro_form->generate_dropdown_content('akun_klass','id_klass','nm_klass');
	}
	
	//dropdown subklass -- has been depreciated
	function get_drdp_subklas()
	{
		//echo $this->zetro_form->generate_dropdown_content('akun_subklass','id_subklass','nm_subklass');
	}
	//get scuence nomor
	function get_nomor()
	{
		$n=0;$nnx=0;
		$id=$_POST['id'];
		$n=$this->main_model->rdb('akun',"max(ckode) as jml","where cid_parent='".$id."'");
		$cn=$this->main_model->rdb('akun',"igrup","where ckode='".$id."'");
		/*$nn=explode('.',$n);
			if(strlen((int)$nn[(count($nn)-1)])==1)
			{
				$nnx='0'.((int)$nn[(count($nn)-1)]+1);
			}*/
		if(((int)substr($n,3,2)+1)<10)
		{ 
			$nnx=$id.'0'.((int)substr($n,3,2)+1);
		}else{
			$nnx=$id.((int)substr($n,3,2)+1);
		}
		echo ($nnx.":".$cn.":". substr($n,3,2));
	}
	function get_akun_calc()
	{
		$n=0;
		$id=$_POST['id'];
		$n=$this->main_model->rdb('akun',"igrup","where cid_parent='".$id."'");
		echo $n;
	}
	function get_nomor_parent()
	{
		$n=0;
		$id=$_POST['id'];
		$n=$this->main_model->rdb('v_akun_parent',"max(ckode) as jml","where cid_parent='".$id."'");
		echo (($n+1));
	}
	//detail akun
	function get_detail_akun()
	{
		$data=array();
		$id	 =$_POST['id'];
		$tab	=empty($_POST['tab'])?'':$_POST['tab'];
		$field  =empty($_POST['field'])?'':$_POST['field'];
		$this->main_model->table_name('akun');
		$this->main_model->set_methods('select');
		$this->main_model->query();
		$this->main_model->where(array('ckode'=>$id));
		$data=$this->main_model->set_data();
		echo json_encode($data[0]);	
	}
	//cost center ============================================================
	/**
		View for set akun contra for auto jurnal
	*/
	function akun_cc()
	{
			$data=array();
			$data['tab_header']=$this->zetro_form->generate_tab_header('Cost Center');
			$this->zetro_form->frm_file('asset/frm/zetro_akun.frm');
			$this->zetro_auth->menus('cost_center');
			//create list
			$content='';
			$this->zetro_form->section('listcc');
			$this->zetro_form->action_col(true);
			$this->zetro_form->tabel_content($content);
			$data['list']=$this->zetro_form->list_std('NewList','80%');
			$this->zetro_auth->menus('kode_akun');
			//create modal
			$this->zetro_form->addButtons();
			$this->zetro_form->buttons(false,'Simpan');
			$this->zetro_form->section('CostCenter');
			$this->zetro_form->tp_ahead();
			$this->zetro_form->Modale('frm1');
			$data['modal']=$this->zetro_form->dialog($this->zetro_form->frm_std('frm1','80%'),'Add Cost Center','',($this->zetro_auth->cek_oto('c')!='')?true:false);

			$this->zetro_form->buttons(false,'Simpan');
			$this->zetro_form->section('frmcc');
			$this->zetro_form->tp_ahead();
			$this->zetro_form->Modale('frm1');
			$data['modal2']=$this->zetro_form->dialog($this->zetro_form->frm_std('frm2','80%'),'Add Akun','2',($this->zetro_auth->cek_oto('c')!='')?true:false,'',false,2);
			$this->load->view('admin/header');
			$this->load->view('accounting/akun_cc',$data);
			$this->load->view('admin/footer');
	}
	/** 
		List of aktiva akun for set pasiva akun
	*/
	function getlistcc()
	{
		$content='';$n=0;$data=array();
			$this->main_model->table_name('akun_cc_head');
			$this->main_model->query();
			//empty($_POST['cari'])?'':$this->main_model->where_like('cnama',$_POST['cari'],'both');
			$this->main_model->set_methods('select');
			$lst_usr=$this->main_model->set_data();
			$this->zetro_auth->menus('kontra_akun');
			
			foreach($lst_usr as $r)
			{
				$n++; $x=0;
				$icon=($this->zetro_auth->cek_oto('c')!='')?
				$this->zetro_form->z_icon($r->id_cc.":".$r->kd_cc,array('cus-add'),array('Add_akun_kredit')):'';
				$icon2=($this->zetro_auth->cek_oto('c')!='')?
				$this->zetro_form->z_icon($r->id_cc.":".$r->kd_cc,array('cus-add'),array('Add_akun_debet')):'';
				$icon3=($this->zetro_auth->cek_oto('c')!='')?
				$this->zetro_form->z_icon($r->id_cc,array('cus-folder','cus-cross'),array('edit','delete')):'';

				$content.=tr('alert alert-succes').td($n,'',false,'','center').
						  td($r->kd_cc,'',false,'','center').
						  td($r->nm_cc,'',false).
						  td($icon2,'',false,'','center').
						  td($icon,'',false,'','center').
						  td($icon3,'',false,'','center').
						 _tr();
					$this->main_model->table_name('akun_cc_detail');
					$this->main_model->query();
					$this->main_model->where(array('kd_cc'=>$r->kd_cc,'parent_cc <>'=>'0'));
					$this->main_model->set_methods('select');
					$data=$this->main_model->set_data();
					foreach($data as $d)
					{
						$x++;
					$icons=($this->zetro_auth->cek_oto('e')!='')?
					$this->zetro_form->z_icon($d->id_cc,array('cus-','cus-cross'),array('','hapus')):'';
					$content.=tr().td('','',false,'','center').
							  td('','',false,'','right').
							  td(nbs(5).$x.". ".$d->id_akun." - ".$d->nm_cc,'',false).
							  td(($d->id_calc==0)?$this->zetro_form->z_icon($d->id_cc,array('cus-tick'),array('Status Debet')):'','',false,'','center').
							  td(($d->id_calc==1)?$this->zetro_form->z_icon($d->id_cc,array('cus-tick'),array('Status Kredit')):'','',false,'','center').
							  td($icons,'',false,'','center').
							 _tr();
					}
			}
			$content.=$this->zetro_form->DataNotFound($lst_usr,5);
			echo $content;
	}
	function setakuncc()
	{
		$data=array();
		$data['id_cc']=empty($_POST['id_cc'])?0:$_POST['id_cc'];
		$data['kd_cc']=empty($_POST['kd_cc'])?'':strtoupper(addslashes($_POST['kd_cc']));
		$data['nm_cc']=empty($_POST['nm_cc'])?'':addslashes($_POST['nm_cc']);
		$data['created_by']=$this->session->userdata('userid');
			$this->main_model->prepared_data('akun_cc',$data);
			echo success($this->main_model->set_data());
	}
	function setkontraakun()
	{
		$data=array();
			$ket=explode(":",$_POST['kd_akun']);
			$data['id_cc']=empty($_POST['id'])?'0':$_POST['id'];
			$data['kd_cc']=empty($_POST['kd_cc2'])?'':$_POST['kd_cc2'];
			$data['nm_cc']=empty($_POST['fldnm'])?'':$_POST['fldnm'];;
			$data['fld_name']=empty($_POST['fld_name'])?'':$_POST['fld_name'];
			$data['id_akun']=empty($_POST['kd_akun'])?'':$_POST['kd_akun'];	
			$data['parent_cc']=empty($_POST['id_cc2'])?'0':$_POST['id_cc2'];
			$data['id_calc']=empty($_POST['stat_cc'])?'0':$_POST['stat_cc'];
			$data['created_by']=$this->session->userdata('userid');
			$this->main_model->prepared_data('akun_cc',$data);
			echo success($this->main_model->set_data());
		
	}
	function delheadcc()
	{
		$id=$_POST['id'];	
		$this->main_model->hapus_data('akun_cc','parent_cc',$id);	
	}
	function delakunkontra()
	{
		$id=$_POST['id'];	
		$this->main_model->hapus_data('akun_cc','id_cc',$id);	
	}
	//saldo awal
	function saldo_awal()
	{
			$this->load->view('admin/header');
			//$this->load->view('accounting/unit_bussiness',$data);
			$this->load->view('admin/footer');
	}

	//unit bussiness
	
	function unit_bussines()
	{
			$data=array();
			$data['id_unit']=$this->zetro_auth->menus('unit_bussiness');
			$data['tab_header']=$this->zetro_form->generate_tab_header('Unit Bussiness');
			$this->zetro_form->frm_file('asset/frm/zetro_akun.frm');
			$this->zetro_auth->menus('unit_bussiness');
			$content='';
			$this->zetro_form->section('unitbussines');
			$this->zetro_form->action_col(true);
			$this->zetro_form->tabel_content($content);
			$data['list']=$this->zetro_form->list_std('NewList','50%');
			$data['modal']='';
			//send data to view
			$this->load->view('admin/header');
			$this->load->view('accounting/unit_bussiness',$data);
			$this->load->view('admin/footer');
		
	}
	
	function set_unitbussiness()
	{
		$data=array();
		$data['id_unit']  =empty($_POST['id_unit'])?'0':$_POST['id_unit'];
		$data['nm_unit']  =addslashes($_POST['nm_unit']);
		$data['created_by']=$this->session->userdata('userid');
		$this->main_model->prepared_data('akun_unitbussiness',$data);
		echo success($this->main_model->set_data());
	}
	function get_unit_list()
	{
			$content='';$i=0;$lst_usr=array();$ck='';
			$ordby=empty($_POST['ordby'])?'id_unit':$_POST['ordby'];
			$this->main_model->table_name('akun_unitbussiness');
			$this->main_model->query();
			$this->main_model->orderby($ordby);
			$this->main_model->set_methods('select_ordered');
			$lst_usr=$this->main_model->set_data();
			$this->zetro_auth->menus('unit_bussiness');
			foreach($lst_usr as $r)
			{
				$i++;
				$ck=$this->main_model->rdb('akun','id_unit',"where id_unit='".$r->id_unit."'");
				$icon=($this->zetro_auth->cek_oto('e')!='' && $ck=='')?
					  $this->zetro_form->z_icon($r->id_unit.":".$r->nm_unit,array('cus-page-white-edit','cus-cross'),array('edit','deleted')):
					  $this->zetro_form->z_icon($r->id_unit.":".$r->nm_unit,array('cus-page-white-edit','cus-cross'),array('edit','del'));
				$content.=tr().td($i,false,'','','center').
						  td($r->nm_unit).
						  td($icon,false,'','','center')._tr();
			}
				$content.=$this->zetro_form->DataNotFound($lst_usr,3);
				echo $content;
				
	}
	
	function del_unit()
	{
		$id=$_POST['id'];
		$this->main_model->hapus_data('akun_unitbussiness','id_unit',$id);	
	}
	
	function account_set()
	{
			$data=array();
			$data['id_unit']=$this->zetro_auth->menus('setting_rekenig');
			$data['tab_header']=$this->zetro_form->generate_tab_header('Setting Akun');
			$this->zetro_form->frm_file('asset/frm/zetro_akun.frm');
			$this->zetro_auth->menus('setting_rekenig');
			$content='';
			$this->zetro_form->section('akunset');
			$this->zetro_form->action_col(true);
			$this->zetro_form->tabel_content($content);
			$data['list']=$this->zetro_form->list_std();
			
			$this->zetro_form->buttons(true,'Simpan');
			$this->zetro_form->section('newAset');
			//$data['frm']=$this->zetro_form->frm_std('frm1','75%');
			$this->zetro_form->AddFields("<input type='hidden' id='iid_setting' name='iid_setting' value=''/>");
			$this->zetro_form->Modale('frm1');
			$data['modal']=$this->zetro_form->dialog($this->zetro_form->frm_std(),'Setting Akun');
			//send data to view
			$this->load->view('admin/header');
			$this->load->view('accounting/akun_setting',$data);
			$this->load->view('admin/footer');
	}
	
	function account_set_list()
	{
			$content='';$i=0;$lst_usr=array();$ck='';
			$ordby=empty($_POST['ordby'])?'iid_parent':$_POST['ordby'];
			$this->main_model->table_name('v_akun_setting');
			$this->main_model->query();
			$this->main_model->orderby($ordby);
			$this->main_model->set_methods('select_ordered');
			$lst_usr=$this->main_model->set_data();
			$this->zetro_auth->menus('setting_rekenig');
			foreach($lst_usr as $r)
			{
				$i++;
				$icon=($this->zetro_auth->cek_oto('e')!='' && $ck=='')?
					  $this->zetro_form->z_icon($r->iid_setting,array('cus-page-white-edit','cus-cross'),array('edit','deleted')):
					  $this->zetro_form->z_icon($r->iid_setting,array('cus-page-white-edit','cus-cross'),array('edit','del'));
				$content.=tr().td($i,false,'','','center').
						  td($r->vparent,false,'','','left\' nowrap=\'nowrap').
						  td($r->vnama).
						  td($r->ckode).
						  td($r->cnama).
						  td($r->ckodemin).
						  td(($r->imin=='ya')?$this->main_model->rdb('akun','cnama',"where ckode='".$r->ckodemin."'"):'').
						  td($r->itipe,false,'','','left\' nowrap=\'nowrap').
						  td($r->aktif,false,'','','center').
						  td($icon,false,'','','center')._tr();
			}
				$content.=$this->zetro_form->DataNotFound($lst_usr,3);
				echo $content;
	}
	function set_account_set()
	{
		$data=array();
		$vp=explode('.',$_POST['iid_parent']);	
		$data['iid_setting'] =empty($_POST['iid_setting'])?'0':$_POST['iid_setting'];
		$data['vnama']	   =empty($_POST['vnama'])?''	   :addslashes($_POST['vnama']);
		$data['iid_parent']  =empty($_POST['iid_parent'])?''  :$vp[0];
		$data['ckode']	   =empty($_POST['ckode'])?''	   :$_POST['ckode'];
		$data['ckodemin']    =empty($_POST['ckodemin'])?''	:$_POST['ckodemin'];
		$data['itipe']	   =empty($_POST['itipe'])?''	   :$_POST['itipe'];
		$data['imin']	    =empty($_POST['imin'])?'tidak'   :$_POST['imin'];
		$data['aktif']	   =empty($_POST['aktif'])?'ya'	 :$_POST['aktif'];
		$data['vparent']     =empty($vp[1])?'':$vp[1];
		$this->main_model->prepared_data('akun_setting',$data);
		echo success($this->main_model->set_data());
	}
	function get_account_set_detail()
	{
		$data=array();
		$id	 =$_POST['id'];
		$this->main_model->table_name('akun_setting');
		$this->main_model->set_methods('select');
		$this->main_model->query();
		$this->main_model->where(array('iid_setting'=>$id));
		$data=$this->main_model->set_data();
		echo json_encode($data[0]);	
	}
	function del_set_account()
	{
		$id=$_POST['id'];
		$this->main_model->hapus_data('akun_setting','iid_setting',$id);	
	}
	function drdwn()
	{
			$content='';$i=0;$lst_usr=array();$ck='';
			$tabel	=$_POST['tabel'];
			$fld	  =$_POST['fld'];
			$nfld	 =explode('-',$_POST['nfld']);
			//$nfld	=is_array($nfl)?$nfl:$_POST['nfld'];
			$ordby=empty($_POST['ordby'])?'id':$_POST['ordby'];
			$this->main_model->table_name($tabel);
			$this->main_model->query();
			$this->main_model->orderby($ordby);
			$this->main_model->set_methods('select_ordered');
			$lst_usr=$this->main_model->set_data();
			$content="<option value=''>&nbsp;</option>";
			foreach($lst_usr as $r)
			{
				$m=(strlen($r->$nfld[0])==1)?"style='background:#fffecc'":"";
				if($tabel!='akun')
				{
					$content.=(empty($nfld[1]))?"<option value='".$r->$fld."'>".$r->$nfld[0]."</option>":"<option value='".$r->$fld.'.'.$r->$nfld[1]."'>".$r->$nfld[0].'.'.$r->$nfld[1]."</option>";
				}else{
					$content.="<option value='".$r->$fld."'".$m.">".nbs((strlen($r->$nfld[0])-1)).$r->$nfld[0].' '.$r->$nfld[1]."</option>";
				}
			}
			echo $content;
	}
	
	function list_akun()
	{
			//collect data klasifikasi
			$content='';$n=0;
			$ordby=empty($_POST['ordby'])?'cid_parent':$_POST['ordby'];
			$this->main_model->table_name('v_akun_parent');
			$this->main_model->query();
			//$this->main_model->orderby($ordby);
			$this->main_model->set_methods('select');
			$lst_usr=$this->main_model->set_data();
			$content="<ul id='navigation' class='treeview'>";
				foreach($lst_usr as $r)
				{
					//collect sub tab 1
					$ordby=empty($_POST['ordby'])?'ckode':$_POST['ordby'];
					$this->main_model->table_name('v_akun_subklas');
					$this->main_model->query();
					$this->main_model->where(array('cid_parent'=>$r->ckode));
					$this->main_model->orderby($ordby);
					$this->main_model->set_methods('select_ordered');
					$sbklas=$this->main_model->set_data();/**/
		
					$n++;$x=0;
					$content.="<li class='folder'><a onclick=\"btn_click('e:".$r->ckode.":".$r->cnama."','akun');\">".$r->ckode." ".$r->cnama."</a>";
						foreach($sbklas as $rr)
						{
							$x++;$z=0;
							//sub tab 2
							$ordby=empty($_POST['ordby'])?'ckode':$_POST['ordby'];
							$this->main_model->table_name('akun');
							$this->main_model->query();
							$this->main_model->where(array('cid_parent'=>$rr->ckode));
							$this->main_model->orderby($ordby);
							$this->main_model->set_methods('select_ordered');
							$akn=$this->main_model->set_data();/**/
							$content.="<ul><li class='folder'><a onclick=\"btn_click('e:".$rr->ckode.':'.$rr->cnama."','akun');\">".$rr->ckode.'. '.$rr->cnama."</a>";
								foreach($akn as $rrr)
								{
									$z++;
										//sub tab 3
										$ordby=empty($_POST['ordby'])?'ckode':$_POST['ordby'];
										$this->main_model->table_name('akun');
										$this->main_model->query();
										$this->main_model->where(array('cid_parent'=>$rrr->ckode));
										$this->main_model->orderby($ordby);
										$this->main_model->set_methods('select_ordered');
										$akne=$this->main_model->set_data();/**/
										$content.="<ul><li class='folder'><a onclick=\"btn_click('e:".$rrr->ckode.':'.$rrr->cnama."','akun');\">".$rrr->ckode.'. '.$rrr->cnama."</a>";
											foreach($akne as $rrre)
											{
												$content.="<ul><li class='treeview'><a onclick=\"btn_click('e:".$rrre->ckode.':'.$rrre->cnama."','akun');\">".$rrre->ckode.'. '.$rrre->cnama."</a><li>";
											}
										$content.="</ul></li>";
								}
							$content.="</ul></li>";
						}
					$content.="</ul></li>";
				}
			 $content.="</ul>";
			echo $content;
	}
	//cost center
	
	function get_akun_tphead()
	{
		$data=array();$akuns='';//array();
		//$where=array('igrup'=>$_POST['igrup']);
		$this->main_model->table_name('v_akun_display');
		$this->main_model->query();
		//$this->main_model->where($where);
		$this->main_model->set_methods('select');
		$data=$this->main_model->set_data();
		//$akuns='[';
		foreach($data as $r)
		{
			$akuns[]=$r->kodeakun;
		}
		//$akuns.=']';
		echo json_encode($akuns);
	}

//end of akun class
}